//
//  JourneyListTableViewCell.m
//  WildDonkey
//
//  Created by 孙俊 on 15/3/27.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "JourneyListTableViewCell.h"
#import "JourneyListTableViewCell.h"
#import "UIImageView+WebCache.h"
#define topgap 10
#define gap 5
@implementation JourneyListTableViewCell

- (void)dealloc
{
	[_sj_textLabel release];
	[_sj_textLabel release];
	[_sj_picView release];
	[super dealloc];
}

- (void)awakeFromNib {
	// Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
	[super setSelected:selected animated:animated];
	
	// Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
	self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
	if (self) {
		
		CGRect rect = [UIScreen mainScreen].bounds;
		
		CGFloat width = rect.size.width;
		
		//底层视图
		UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, width - 20, 140)];
		bgView.backgroundColor = [UIColor clearColor];
		
		//白底毛玻璃效果层
		UIView *bgView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width - 20, 140)];
		[bgView1 setBackgroundColor:[UIColor whiteColor]];
		bgView1.alpha = 0.3;
		[bgView addSubview:bgView1];
		
		CGFloat imageWidth = (bgView.frame.size.width - 10)/ 2;
		CGFloat imageHeight = imageWidth / 2;
		
		
		//图片
		_sj_picView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, imageWidth, imageHeight)];
		_sj_picView.layer.cornerRadius = 20;
		_sj_picView.backgroundColor = [UIColor grayColor];
		_sj_picView.image = [UIImage imageNamed:@"占位"];
		_sj_picView.alpha = 1;
		_sj_picView.layer.masksToBounds = YES;
		[bgView addSubview:_sj_picView];
		
		CGFloat titleWidth = imageWidth;
		CGFloat titleHeight = 35;
		
		//标题
		_sj_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(5 , 95, titleWidth, titleHeight)];
//		_sj_titleLabel.backgroundColor = [UIColor redColor];
		_sj_titleLabel.numberOfLines = 1;
		_sj_titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
		_sj_titleLabel.font = [UIFont systemFontOfSize:16];
		_sj_titleLabel.textColor = [UIColor blackColor];
		_sj_titleLabel.textAlignment = NSTextAlignmentCenter;
		[bgView addSubview:_sj_titleLabel];
		
		CGFloat textX = imageWidth + 10;
		CGFloat textWidth = width - imageWidth - 30;
		CGFloat textHeight = imageHeight + titleHeight;
		
		//简介
		_sj_textLabel = [[UILabel alloc] initWithFrame:CGRectMake(textX, 5, textWidth, textHeight)];
		//		_sj_textLabel.backgroundColor = [UIColor redColor];
		_sj_textLabel.numberOfLines = 0;
		_sj_textLabel.lineBreakMode = NSLineBreakByTruncatingTail;
		_sj_textLabel.font = [UIFont systemFontOfSize:14];
		[bgView addSubview:_sj_textLabel];
		
		
		[self.contentView addSubview:bgView];
		[bgView release];
		
	}
	return self;
}

- (void)setData:(JourneyListData *)data
{
	if (_data != data) {
		[_data release];
		_data = [data retain];
		
		
		_sj_titleLabel.text = data.title;
		_sj_textLabel.text = data.desc;
		
		
		
		
		
////		NSURL *url = [NSURL URLWithString:data.img];
//		NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20];
//		NSData *data1 = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
		[self.sj_picView setImageWithURL:[NSURL URLWithString:data.img]];
		
		NSLog(@"游记列表 cell 文字赋值成功");
		
	}
}

@end
